package com.niit.service.impl;

import com.niit.dao.OrderMapper;
import com.niit.pojo.Reservation;
import com.niit.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Transactional(rollbackFor = Exception.class)
    public void saveReservationAndUpdateConsumer(Reservation reservation) {
        orderMapper.saveReservation(reservation);
        orderMapper.updateConsumerReservationResult(reservation);
    }

    @Override
    public void DeleteReservatoinByBillId(String bill_id) {
        orderMapper.DeleteReservatoinByBillId(bill_id);
    }

    @Override
    public void updateReservationStatus(String bill_id, String status) {
        Map<String, String> map = new HashMap<>();
        map.put("bill_id", bill_id);
        map.put("status", status);
        orderMapper.UpdateReservationStatus(map);
    }

    public Reservation getByReservationResult(String reservationResult) {
        return orderMapper.getByReservationResult(reservationResult);
    }

    @Override
    public void saveReservation(Reservation reservation) {
        // 实现保存预订信息的逻辑
        orderMapper.saveReservation(reservation);
    }

    @Override
    public boolean isReservationResultExists(String reservationResult) {
        Reservation existingReservation = orderMapper.getByReservationResult(reservationResult);
        return existingReservation != null;
    }

    @Override
    public List<Reservation> getAllReservation() {
        return orderMapper.getAllReservation();
    }

    @Override
    public List<Reservation> getReservationsById(String consumer_id) {
        return orderMapper.getReservationsById(consumer_id);
    }

    @Override
    public List<Reservation> getReservationsByWindowId(String window_id) {
        return orderMapper.getReservationsByWindowId(window_id);
    }
}
